React应用上的GoogleAnalytics(分析)不起作用 您所在的位置:网站首页 android pageview React应用上的GoogleAnalytics(分析)不起作用

React应用上的GoogleAnalytics(分析)不起作用

2023-01-01 16:02| 来源: 网络整理| 查看: 265

1> Erik Martín ..:

您需要在componentDidMount和componentDidUpdate中生成综合浏览量:

compOnentDidMount= () => ReactGA.pageview(window.location.pathname + window.location.search); compOnentDidUpdate= () => ReactGA.pageview(window.location.pathname + window.location.search);

因此,最终代码:

import React, { Component } from "react"; import HeaderList from "./components/Header"; import "./App.css"; import { Layout } from "antd"; import { Router, Route, Switch } from "react-router-dom"; import createHistory from "history/createBrowserHistory"; import ReactGA from 'react-ga'; import Keys from './config/keys'; import AboutMe from "./components/AboutMe"; import Skills from "./components/Skills"; import Contact from "./components/Contact"; import Projects from "./components/Projects"; const { Content } = Layout; ReactGA.initialize(Keys.GOOGLE_TRACKING_ID); //Unique Google Analytics tracking number class App extends Component { compOnentDidMount= () => ReactGA.pageview(window.location.pathname + window.location.search); compOnentDidUpdate= () => ReactGA.pageview(window.location.pathname + window.location.search); render() { return ( ); } } export default App;


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有